
clear 
include "$CODE/pathnames"

* Ensure Stata looks in the local ado folder first
adopath ++ "`c(pwd)'/ado"
* Verify ado path order
adopath


********************************************************************************
**** FIGURE 1: List Experiment Estimates of Peer Pressure in Protest Participation

* NOTE: The original figure is created in Excel; the code here reproduces the figure not exactly, but in a general sense.

use "$DATA/data_list_experiment_final.dta", clear

global control0=""
global control1="$control0 i.moscow i.stpeter i.income"
global control2="$control1 i.Referer"
global control3="$control2 i.job"
global control4="$control3 i.sex age agesq i.educ"

eststo: xi: reg v16_1 i.group_1 $control4 if dumprot==1, r
matrix results = e(b)' 
matrix var_matrix = e(V) 
matrix results = results[1..3,1]
matrix var_matrix = var_matrix[1..3, 1..3]
local num_coef = rowsof(results)
matrix se_matrix = J(`num_coef', 1, .)
forvalues i = 1/`num_coef' {
    matrix se_matrix[`i',1] = sqrt(var_matrix[`i',`i']) 
}
matrix ci_low  = results - 1.96 * se_matrix
matrix ci_high = results + 1.96 * se_matrix

clear
svmat results, name(beta)
svmat ci_low, name(ci_l)
svmat ci_high, name(ci_h)
gen question = _n  
replace question = 0 if question == 3
replace question = 3 if question == 2
replace question = 2 if question == 0

label define group_labels 1 "Many of my friends and acquaintances participate" ///
                         2  "I wanted to tell friends and acquaintances about it" ///
                         3 "I wanted to tell about it in social media" 
label values question group_labels

twoway (bar beta question, barwidth(0.5) color(blue%40)) /// 
    (rcap ci_h ci_l question, lcolor(black)), /// 
    xlabel(1 "Many of my friends and acquaintances participate" ///
	       2 "I wanted to tell friends and acquaintances about it"  ///
           3 "I wanted to tell about it in social media", ///
           labsize(2) angle(0)) /// 
    ylabel(0(0.1)0.6, labsize(small) format(%9.1f)) ///
    title("Why did you participate in protests?", size(medium)) ///
    legend(off) ///
	xtitle(" ")
graph export "$REPLICATION/Figures_MainText/figure_1.pdf", as(pdf) replace

********************************************************************************
**** FIGURE 2: Online Protest Group Membership and SPbSU Student Cohorts.

use "$DATA/data_crosscity_analysis_final.dta", clear

global control4="pop pop_2 pop_3 pop_4 pop_5 ac dp dm city2 logwage11 lA20_24_y2010 lA25_29_y2010 lA30_34_y2010 lA35_39_y2010  lA40_44_y2010 lA45_49_y2010 lA50_more_y2010 he2010_A20_24 he2010_A25_29 he2010_A30_34 he2010_A35_39 he2010_A40_44 he2010_A45_49 he2010_A50_more University_exists educ2002 ip_2011 logok2014 ef2010"
global err="robust"

forval i = 1/3 {
	ivreg2 loggroup logspbsu`i' $control4 logoldprot if sample 
	estimates store e`i'
}

#d ;
coefplot (e1, keep(logspbsu1)) (e2, keep(logspbsu2)) (e3, keep(logspbsu3)),  xline(0) levels(90) 
			coeflabels(logspbsu3="Log (SPbSU students), one cohort older than VK founder" 
			logspbsu2="Log (SPbSU students), same 5-year cohort as VK founder"  
			logspbsu1="Log (SPbSU students), one cohort younger than VK founder", wrap(30) 
			labsize(small)) title("VK online protest group membership" 
			"and coefficients for the number of SPbSU students over time", size(medsmall) span)  
			order(logspbsu3 logspbsu2  logspbsu1) xlabel(-0.3(0.1)0.5) ciopts(recast(rcap) lc(navy)) 
			legend(off) offset(0) graphr(c(white)) mcolor(navy) ;
#d cr
graph export "$REPLICATION/Figures_MainText/figure_2.pdf", as(pdf) replace

********************************************************************************
**** FIGURE 3: Dynamic Impact of VK Membership on Protest Participation

drop n_ave_x logprot_ave
matrix A=J(42,4,0)
forval i = 1/42 {
	preserve
	keep if week_year_n <= `i'
	bysort OKATO: egen n_ave_x = mean(n_ave)
	gen logprot_ave = log(1+n_ave_x)
	qui ivreg2 logprot_ave logspbsu1 logspbsu3 $control4 logoldprot (logvk = logspbsu2) if week_year_n == 1 , cluster(okato_reg)
	matrix A[`i',1] = _b[logvk]
	matrix A[`i',2] = _se[logvk]
	matrix A[`i',3] = `i'
	qui sum prot_num_week if week_year_n == `i'
	matrix A[`i',4] = r(mean)
	display `i'
	restore
}

svmat A
gen A5 = A1-1.96*A2
gen A6 = A1+1.96*A2

twoway scatter A1 A3 if A1!=0 & A1!=. , mcolor(black) msize(medlarge) ///
 || rcap A5 A6 A3 if A1!=0 & A1!=. , lc(black) yaxis(1) lw(medthick) ///
 || , scheme(s2mono) graphr(c(white)) yline(0, lc(gs12)) ysize(5) xsize(6) ///
  xtitle("Total Weeks, Starting Dec 4, 2011") legend(off) xlabel(1 5(5)40, angle(45)) ///
  title("Average Number of Protesters") ytitle("IV coefficient, log VK users")
graph export "$REPLICATION/Figures_MainText/figure_3.pdf", as(pdf) replace
